#!/bin/bash

source /etc/profile
if [ $# -eq 1 ]; then
	targetHour=$1
else
	targetHour=`date -d "-1 hours" +"%Y%m%d%H"`
fi
path=$(cd $(dirname $0);pwd)
parentPath=$(dirname ${path})
targetDate=${targetHour:0:8}
day=$(date -d"${targetDate}" "+%Y-%m-%d")
echo $targetHour
#清洗小时数据
sh ${path}/format_log/run_format_hour_log_v2.sh ${targetHour}
#获取转化的配置文件
source ${path}/configs/mysql_config
#页面转化
python ${path}/get_conversion_config.py ${host} ${port} ${user} ${password} ${db} "get_page_config" > ${path}/page.txt
#事件转化
python ${path}/get_conversion_config.py ${host} ${port} ${user} ${password} ${db} "get_event_config" > ${path}/event.txt
#时长转化
python ${path}/get_conversion_config.py ${host} ${port} ${user} ${password} ${db} "get_time_config" > ${path}/time.txt
#页数转化
python ${path}/get_conversion_config.py ${host} ${port} ${user} ${password} ${db} "get_pagenum_config" > ${path}/pagenum.txt
wait
analysis_job=`cat << EOF
analysis_behaviour/analysis_behaviour.sh
analysis_conversion/analysis_conversion.sh
analysis_event/analysis_event.sh
analysis_referer/analysis_referer.sh
analysis_visitors/analysis_visitors.sh
overview/overview.sh
tools/filter_ip.sh
tools/filter_keyword.sh
EOF
`
for job in ${analysis_job[@]}
do
{
	jobname=`basename ${job} .sh`
	wait
	echo "sh ${path}/${job} ${targetHour}"
	(echo "--${targetHour} begin--";sh ${path}/${job} ${targetHour};echo "--${targetHour} success--") > ${path}/logs/${jobname}.log 2>&1
}&
done
wait
#指标预测
if [ ${targetHour:8:2} -eq "23" ];then
	sh ${path}/analysis_quota_forecast/analysis_quota_forecast.sh ${targetHour}
fi
echo "$targetHour job success"
echo "$targetHour job success" | mail -s "$targetHour job success" auto.reporter@nsw81.com